package com.wn.inventory.web;

import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.Hr;
import com.wn.entity.OutWarehouseApplication;
import com.wn.inventory.service.OutWarehouseApplicationService;
import com.wn.inventory.vo.OutWarehouseApplicationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ author     ：NST
 * @ date       ：Created in 2022/10/21 16:46
 * @ description：
 * @ modified By：
 * @ version:
 */
@RestController
@RequestMapping("inventory/out")
public class OutWarehouseApplicationController {
    @Autowired
    OutWarehouseApplicationService outWarehouseApplicationService;

    /**
     * @param outWarehouseApplication
     * @return com.wn.common.ResponseEntity
     * @ author nst
     * @ date 2022/10/21 16:49
     * @ Description 前端需提供库存台账id,数量,用途
     */
    @RequestMapping("add")
    public ResponseEntity add(@RequestBody @Validated OutWarehouseApplication outWarehouseApplication, HttpServletRequest request) {
        Hr hr = new Hr();
        hr.setId(Integer.parseInt(request.getHeader("userId")));
        outWarehouseApplication.setApplicant(hr);
        outWarehouseApplicationService.insert(outWarehouseApplication,request);
        return ResponseEntity.success;
    }

    /**
     * @param outWarehouseApplicationVo
     * @return com.wn.common.ResponseEntity
     * @ author nst
     * @ date 2022/10/21 16:50
     * @ Description 多条件分页查询出库申请信息
     */
    @RequestMapping("addition")
    public ResponseEntity getByCondition(@RequestBody OutWarehouseApplicationVo outWarehouseApplicationVo) {
        PageBean<OutWarehouseApplication> pageBean = outWarehouseApplicationService.getByCondition(outWarehouseApplicationVo);
        return new ResponseEntity(pageBean);
    }


}
